'use strict';

const Service = require('egg').Service;

class ClassifyService extends Service {
    async lClassify() {
        return await this.app.mysql.query('select * from classify where pid=0')
    }

    async rClassify(pid){
        let rArr = await this.app.mysql.query('select * from classify where pid=?',[pid]);

        /**
         * [
         *      {
         *            title:'休闲零食',
         *            list:[
         *                  {
         *                      膨化食品
         *                  }
         *             ]
         *      }
         * ]
         * 
        */

        let data = [];

        for(let i = 0;i<rArr.length;i++){
            let list = await this.app.mysql.query('select * from classify where pid=?',[rArr[i].id]);
            data.push({
                title:rArr[i].title,
                list
            })
        }
        return data
    }
}

module.exports = ClassifyService;
